﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for ThamSoCtr
/// </summary>
public class ThamSoCtr
{
	public ThamSoCtr()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public DataTable layBangThamSo()
    {
        try
        {
            string sql = "select * from ThamSo ";
            return DataProvider.GetData(sql);
        }
        catch (Exception ex)
        {
            throw ex;
            //return false;
        }

    }
    public EThamSo layThamSo(string MaThamSo)
    {
        try
        {
            DataTable tableNhaCC = DataProvider.GetData("Select * from ThamSo Where MaThamSo=@MaThamSo", "@MaThamSo", MaThamSo);
            EThamSo ThamSo = new EThamSo();
            ThamSo.MaThamSo = tableNhaCC.Rows[0]["MaThamSo"].ToString();
            ThamSo.SoLan = tableNhaCC.Rows[0]["SoLanMua"].ToString();
            ThamSo.GiaTri = tableNhaCC.Rows[0]["GiaTriGiam"].ToString();
           ThamSo.YNghia = tableNhaCC.Rows[0]["YNghia"].ToString();
           ThamSo.NgayBatDau = DateTime.Parse(tableNhaCC.Rows[0]["NgayBD"].ToString());
           ThamSo.NgayKetThuc = DateTime.Parse(tableNhaCC.Rows[0]["NgayKT"].ToString());
            return ThamSo;
        }
        catch (Exception ex)
        {
            throw ex;
           // return false;
        }
    }
    public bool DeleteThamSo(string MaThamSo)
    {
        try
        {
            DataProvider.ExecuteNonQuery("DELETE FROM ThamSo WHERE MaThamSo=@MaThamSo", "@MaThamSo", MaThamSo);
            return true;
        }
        catch (Exception ex)
        {
           // throw ex;
            return false;
        }
    }
    public bool InsertThamSo(EThamSo ThamSo)
    {
        try
        {
            DataProvider.ExecuteNonQuery("INSERT INTO ThamSo VAlUES(@MaThamSo,@NgayBD,@NgayKT,@TenThamSo,@GiaTri,@YNghia)","@MaThamSo",ThamSo.MaThamSo, "@TenThamSo",ThamSo.SoLan, "@GiaTri",ThamSo.GiaTri,"@NgayBD",ThamSo.NgayBatDau,"@NgayKT",ThamSo.NgayKetThuc, "@YNghia", ThamSo.YNghia);
            return true;
        }
        catch (Exception ex)
        {
            //throw ex;
            return false;
        }
    }
    public bool UpdateThamSo(EThamSo ThamSo)
    {
        try
        {
            DataProvider.ExecuteNonQuery("Update ThamSo set SoLanMua=@TenNhaCC,GiaTriGiam=@DiaChi,YNghia=@DienThoai,NgayBD=@NgayBD,NgayKT=@NgayKT WHERE MaThamSo=@MaNhaCC", "@TenNhaCC", ThamSo.SoLan, "@DiaChi", ThamSo.GiaTri, "@DienThoai", ThamSo.YNghia, "@MaNhaCC", ThamSo.MaThamSo,"@NgayBD",ThamSo.NgayBatDau,"@NgayKT",ThamSo.NgayKetThuc);
            return true;
        }
        catch (Exception ex)
        {
           // throw ex;
            return false;
        }
    }
}